﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Xml;
using OrbitOne.Elmah.Data;
using Elmah;

namespace OrbitOne.Elmah.Presenter
{
    public class ErrorDetailBase : Page
    {
        public Guid ErrorId
        {
            get
            {
                var guid = Guid.Empty;
                if(Request.QueryString["id"] != null)
                {
                    guid = new Guid(Request.QueryString["id"]);    
                }
                return guid;
            }
        }

        public Error ElmahError { get; private set;}
        public ELMAH_Error O1Error { get; private set; }
       
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if(ErrorId != Guid.Empty)
            {
                var provider = new ElmahDataProvider();
                O1Error = provider.Context.ELMAH_Errors.SingleOrDefault(err => err.ErrorId == ErrorId);

                
                ElmahError = new Error();
                var reader = new XmlTextReader(new StringReader(O1Error.AllXml.ToString()));
                ElmahError.FromXml(reader);
            }
        }
    }
}
